#include "stdafx.h"

#include "Pixel.h"

#include "Debug.h"


Pixel::Pixel(){
	init (0, 0, 0, 0, 0, 0, 3);
}


Pixel::Pixel(int x, int y , int r, int g, int b, int alpha, int nChannels) {
	init(x, y, r, g, b, alpha, nChannels); 
}


Pixel::Pixel(int x, int y , int rgb, int alpha, int nChannels) {
	
	init(x, y, rgb, rgb, rgb, alpha, nChannels);
}


Pixel::Pixel(CvPoint point, int r, int g, int b, int alpha, int nChannels) {
	init(point.x, point.y, r, g, b, alpha, nChannels); 
}


Pixel::Pixel(CvPoint point, int rgb, int alpha, int nChannels) {
	init(point.x, point.y, rgb, rgb, rgb, alpha, nChannels); 
}


Pixel::Pixel(int x, int y , CvScalar color, int alpha, int nChannels){
	/* CvScalar is in BGR order */
	init(x, y, (int)(color.val[2]), (int)(color.val[1]), (int)(color.val[0]), (int)(color.val[3]), nChannels);
}


Pixel::Pixel(CvPoint point, CvScalar color, int alpha, int nChannels){
	/* CvScalar is in BGR order */
	init(point.x, point.y, (int)(color.val[2]), (int)(color.val[1]), (int)(color.val[0]), (int)(color.val[3]), nChannels);
}


Pixel::~Pixel() {

	//Debug::message("Deleting Pixel", Debug::LEVEL_TESTING);
	//free(value);
	//delete value;
}


void Pixel::init(int x, int y , int r, int g, int b, int alpha, int nChannels){
	this->x = x;
	this->y = y;
	this->point = cvPoint(x,y);
	
	//this->value = (int*)(malloc(4 * sizeof(int)));
	
	//value[0] = r;
	//value[1] = g;
	//value[2] = b;
	//value[3] = alpha;
	this->r = r;
	this->g = g;
	this->b = b;
	this->alpha = alpha;
	
	this->nChannels = nChannels;
}


/*int* Pixel::getRGB() {
    return value;
}*/
int Pixel::getR() {
    //return value[0];
    return this->r;
}
int Pixel::getG() {
    //return value[1];
    return this->g;
}
int Pixel::getB() {
    //return value[2];
    return this->b;
}
int Pixel::getAlpha() {
	//return value[3];
	return this->alpha;
}
int Pixel::getChannels() {
	return nChannels;
}
int Pixel::getValue() {
    //return (value[0] + value [1] + value[2] + value[3]);
    return (r + g +b + alpha);
}
CvPoint Pixel::getPoint() {
	return point;
}
